﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master/Attendance.master" AutoEventWireup="true" CodeFile="CalendarMgmt.aspx.cs" Inherits="LDAP.Web.View.Attendance.CalendarMgmt" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <title>工作日设定 - <%= SystemName %></title>
    <script type="text/javascript" src="<%= StaticDomain %>/scripts/util/My97DatePicker/WdatePicker.js"></script>
    <style type="text/css">
        .niceTab th {
            line-height:70px;
        }
        .niceTab td {
            height:120px;
        }
        .Wdate {
            height:34px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div>
      <nav class="navbar navbar-default" role="navigation">
        <div class="navbar-header">
          <a class="navbar-brand" href="#">选择月份</a>
        </div>
        <div class="collapse navbar-collapse">
          <form class="navbar-form navbar-left" role="search">
            <div class="form-group">
              <input type="text" class="form-control Wdate" value="<%= Year %>年<%= Month.ToString().PadLeft(2,'0') %>月" id="month" onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy年MM月',minDate:'<%= DateTime.Today.AddMonths(1).Year %>-<%= DateTime.Today.AddMonths(1).Month.ToString().PadLeft(2,'0') %>-01'})" />
            </div>
            <button class="btn btn-default" type="button" id="transfer">确定</button>
          </form>
        </div>
      </nav>
    </div>
    <div>
        <div class="alert alert-info">请选择节假日（含周末）并提交更新</div>
        <div class="alert alert-success" style="display:none">更新成功^_^</div>
        <div class="alert alert-danger" style="display:none"></div>
    </div>
    <table class="niceTab" cellspacing="0" cellpadding="0" border="0">
        <tbody>
            <tr>
                <% for (int i = (int)DayOfWeek.Sunday; i <= (int)DayOfWeek.Saturday; i++)
                   { %>
                       <th><%= System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.DayNames[i] %></th>
                 <%  } %>
            </tr>
            <asp:Literal ID="Calender" runat="server"></asp:Literal>
        </tbody>
    </table>
    <br />
    <p><input type="submit" id="submit" class="btn btn-default btn-lg btn-primary" value="设置工作日" /></p>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#transfer").click(page.transfer);

            $(".niceTab td").click(function () {
                $(this).toggleClass("weekend");
            });

            $("#submit").click(page.submit);
        });

        var page = {
            transfer: function () {
                var date = $("#month").val().match(/\d+/g);
                window.location.href = "/Attendance/CalendarMgmt.aspx?y=" + date[0] + "&m=" + date[1];
                return false;
            },

            submit: function () {
                var weekend = [];
                $.each($(".niceTab td"), function (i, q) {
                    if ($(q).hasClass("weekend") && $(q).html() != "") {
                        weekend.push($(q).html());
                    }
                });
                var year = '<%= Year %>';
                var month = '<%= Month %>';
                $.post("/handler/attendanceMgmt.ashx?action=setCalendar", {year: year, month:month, days: weekend.join(',')}, function(data){
                    if (data && data.code == 1) {
                        $(".alert").hide();
                        $('.alert-success').show();

                        window.setTimeout(function () { $(".alert").hide(); $('.alert-info').show(); }, 3000);
                        return false;
                    }
                    else {
                        $(".alert").hide();
                        $(".alert-danger").show();
                    }
                },"json");
            }
        };
    </script>
</asp:Content>